package com.smartfast4j.demo.bean;

import java.util.HashMap;
import java.util.Map;

/**
 * 给客户端返回的响应数据
 *
 */
public class ResponseResult extends HashMap<String, Object> {
	private static final long serialVersionUID = 1L;

	public static final String CODE = "code";
	public static final String MSG = "msg";
	public static final String DATA = "data";

	public ResponseResult() {
		put(CODE, 0);
	}
	
	public static ResponseResult error() {
		return error(500, "未知异常，请联系管理员");
	}
	
	public static ResponseResult error(String msg) {
		return error(500, msg);
	}
	
	public static ResponseResult error(int code, String msg) {
		ResponseResult responseResult = new ResponseResult();
		responseResult.put(CODE, code);
		responseResult.put(MSG, msg);
		return responseResult;
	}

	public static ResponseResult ok(String msg) {
		ResponseResult responseResult = new ResponseResult();
		responseResult.put(MSG, msg);
		return responseResult;
	}
	
	public static ResponseResult ok(Map<String, Object> map) {
		ResponseResult responseResult = new ResponseResult();
		responseResult.putAll(map);
		return responseResult;
	}
	
	public static ResponseResult ok() {
		return new ResponseResult();
	}

	public ResponseResult put(String key, Object value) {
		super.put(key, value);
		return this;
	}
}
